package com.leedsoft.controller;

import com.google.common.collect.Maps;
import com.leedsoft.common.AjaxReply;
import com.leedsoft.common.Page;
import com.leedsoft.controller.dto.AidTaskDto;
import com.leedsoft.controller.vo.TaskPageVo;
import com.leedsoft.service.AidTaskService;
import org.activiti.engine.TaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("/aid_task")
public class AidTaskContrller {
    @Autowired
    private AidTaskService aidTaskService;
    @Autowired
    private TaskService taskService;
    @RequestMapping("/viewList")
    public ModelAndView viewList(ModelAndView modelAndView){

        modelAndView.setViewName("AidTask/aidTask-list");
        return  modelAndView;
    }

    @RequestMapping("/pageList")
    @ResponseBody
    public Map<String,Object> pageList(TaskPageVo pageVo){
        Page<AidTaskDto> page = aidTaskService.getTaskPage(pageVo);
        Map<String,Object> map = new HashMap<>();
        map.put("total",page.getCount());
        map.put("rows",page.getList());
        return map;
    }

    @RequestMapping("/finish")
    @ResponseBody
    public Map<String,Object> finish(HttpServletRequest request){
        String id = request.getParameter("ID");
        String E = request.getParameter("E");
        Map<String,Object> vals = Maps.newHashMap();
        vals.put("pass", 2);
        vals.put("E",E);
        taskService.complete(id, vals);
        return AjaxReply.success();
    }
}
